package com.meida.boot.handler.app;

import com.meida.common.constants.CommonConstants;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.utils.DateUtils;
import com.meida.module.product.client.entity.ProdMarketing;
import com.meida.module.product.client.entity.ProdTopic;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 限时抢购列表
 *
 * @author zyf
 */
@Component("marketingListHandler")
public class MarketingListHandler implements PageInterceptor<ProdMarketing> {
    @Override
    public void prepare(CriteriaQuery<ProdMarketing> cq, PageParams pageParams, EntityMap params) {
        cq.eq(ProdTopic.class, "state", CommonConstants.ENABLED);
        cq.createJoin(ProdTopic.class);
    }

    @Override
    public void complete(CriteriaQuery<ProdMarketing> cq, List<EntityMap> result, EntityMap extra) {
        for (EntityMap entityMap : result) {
            entityMap.put("nowTime", DateUtils.getDateTime());
        }
    }
}
